
package cn.org.seventh.web.common;

import java.beans.PropertyEditor;

import javax.servlet.http.HttpServletRequest;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.ServletRequestDataBinder;

/**
 * @author <a href="mailto:ji.li@symbio-group.com">Andy</a>
 * @since 2007-11-30 上午12:17:41
 */
public class BindUtils {

    public static BindingResult bind(Object object, HttpServletRequest request) {
        ServletRequestDataBinder binder = new ServletRequestDataBinder(object);
        binder.bind(request);
        return binder.getBindingResult();
    }

    public static BindingResult bind(Object object, HttpServletRequest request,
                                     Class requiredType,
                                     PropertyEditor propertyEditor) {
        ServletRequestDataBinder binder = new ServletRequestDataBinder(object);
        binder.registerCustomEditor(requiredType, propertyEditor);
        binder.bind(request);
        return binder.getBindingResult();
    }
}
